package com.zd.ticketing.quartz;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.zd.common.bean.model.TicketOrder;
import com.zd.common.common.enums.PayStatusEnum;
import com.zd.common.dao.TicketOrderDao;
import com.zd.common.dao.common.FindRequestEntity;
import com.zd.common.dao.common.WhereEnum;

public class ModifyOrder {
	
	private TicketOrderDao ticketOrderDao;

	public TicketOrderDao getTicketOrderDao() {
		return ticketOrderDao;
	}

	public void setTicketOrderDao(TicketOrderDao ticketOrderDao) {
		this.ticketOrderDao = ticketOrderDao;
	}
	
	public void modifyOrderStatus(){
		FindRequestEntity findReq = new FindRequestEntity();
		try {
			findReq.addWhere("status", WhereEnum.EQ, PayStatusEnum.To_be_paid.getKey());
			List<TicketOrder> ticketOrderList = ticketOrderDao.find(findReq);
			if(ticketOrderList != null && ticketOrderList.size() > 0){
				for (TicketOrder ticketOrder : ticketOrderList) {
					Calendar cal = Calendar.getInstance();
					cal.setTime(ticketOrder.getCreateTime());
					cal.add(Calendar.MINUTE, 30);
					if(cal.getTime().compareTo(new Date())  <= 0){
						ticketOrder.setStatus(PayStatusEnum.cancel_order.getKey());
						ticketOrder.setUpdateTime(new Date());
						ticketOrderDao.update(ticketOrder);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
